﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using System.ComponentModel;
using System.Xml;
using EQ1.Elements;

namespace EQ1.Objects {
  public class UIPoint : UIElement, IUIElement<UIPoint> {
    public UIPoint ( UIDocument doc )
      : this( doc , "Point" ) {
    }
    public UIPoint ( UIDocument doc , string name )
      : base( "" , name , "" , doc ) {
      this.X = 0;
      this.Y = 0;
    }

    #region IUIElement<UIPoint> Members

    public void Copy ( UIPoint val ) {
      this.X = val.X;
      this.Y = val.Y;
    }
    public void Validate ( UIPoint val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        UIPoint el = new UIPoint( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    #endregion
    
    public int X {
      get {
        return int.Parse( this.GetElement( "X" ).InnerText );
      }
      set {
        this.Validate( "X" , value.ToString() );
      }
    }
    public int Y {
      get {
        return int.Parse( this.GetElement( "Y" ).InnerText );
      }
      set {
        this.Validate( "Y" , value.ToString() );
      }
    }

  }
}
